import heapq
from collections import defaultdict


def solution(words: str, k: int):
    # 统计频率
    counter = defaultdict(int)
    for word in words:
        counter[word] += 1

    # 最小堆
    hq = []
    # 存储字母顺序
    word_freq = []
    for word, freq in counter.items():
        # 拆包: (值, 频率)
        heapq.heappush(hq, (freq, word))
        word_freq.append(word)
        # 控制长度
        if len(hq) > k:
            heapq.heappop(hq)

    ret = []
    pre_fre = None
    while hq:
        fre, val = heapq.heappop(hq)
        # 加入时判断上一个的频率跟当前的是否一致
        if fre == pre_fre:
            # 判断顺序
            if ret[-1]>val:
                ret.append(val)
            else:
                ret.insert(-1, val)
        else:
            pre_fre = fre
            ret.append(val)

    for i in ret[::-1]:
        print(i)


"""
6
I
Love
Life
I
Love
Coding
2

"""

n = int(input())
input_words = []
for i in range(n):
    input_words.append(input())
k = int(input())

solution(input_words, k)  # I Love

"""
16
redundant
code
total
inc
dangerous
functions
total
cute
standard
dismissed
cyclomatic
complexity
total
cute
cute
inc
3
"""
# ->
"""
cute
total
inc
"""
"""
total
cute
inc
"""